home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wb613_01.zip / GENINDEX.C < prev    next >
C/C++ Source or Header  |  1991-03-15  |  2KB  |  73 lines

  1. /*
  2. ** GENINDEX - Create index from text file.
  3. ** 
  4. ** Support Program for The Window BOSS
  5. **
  6. ** Copyright (c) 1984,1985,1986 - Philip A. Mongelluzzo
  7. ** All rights reserved.
  8. **
  9. **  If you attempt to recompile this program you may have to 
  10. **  adjust the logic to account for the way the various compilers 
  11. **  treat <CR><LF> sequences.  This usually amounts to nothing 
  12. **  more than chaning the "rb" to "r" in the fopen statement.  
  13. */
  14.  
  15. #include <stdio.h>                      /* Standard stuff */
  16. #if AZTEC
  17. #define RD "r"
  18. #else
  19. #define RD "rb"
  20. #endif
  21.  
  22.  
  23. FILE *fopen();                          /* keep the compilers happy */
  24. long ftell();
  25.  
  26. main(argc,argv)
  27. int argc;
  28. char *argv[];
  29. {
  30. FILE *fp;
  31. FILE *fo;
  32. char buf[257];
  33. static char fname[132];
  34. unsigned i;
  35. long pos;
  36. char *p;
  37.  
  38.   if(argc < 2) {                        /* check command line */
  39.     printf("Usage: genindex <filename.ext>");
  40.     exit(1);
  41.   }
  42.  
  43.   p = argv[1];                          /* parse input filename */
  44.   i = 0;
  45.   while(*p) {
  46.     fname[i++] = *p++;
  47.     if(*p == ' ' || *p == '.') break;
  48.   }
  49.   strcat(fname, ".ndx");                /* create output filename */
  50.  
  51.   fp = fopen(argv[1], RD);             /* open input */
  52.   if(!fp) {
  53.     printf("Open failed: %s", argv[1]);
  54.     exit(1);
  55.   }
  56.   printf("Creating: %s\n", fname);      /* say whats going on */
  57.   fo = fopen(fname, "w");               /* open output */
  58.  
  59.   while(fgets(&buf[0],256,fp)) {        /* read lines till eof */
  60.     if(buf[0] == '%') {                 /* look for subject heading key */
  61.       fputs(buf, fo);                   /* write to index file */
  62.       fputs(buf, stdout);               /* display on console */
  63.       pos = ftell(fp);                  /* get file position */
  64.       printf("%ld\n", pos);             /* display on console */
  65.       fprintf(fo, "%ld\n", pos);        /* write in output file */
  66.     }
  67.   }
  68.   fclose(fp);                           /* close files */
  69.   fclose(fo);
  70. }
  71.  
  72. /* End */
  73.